package com.server.mock;

import java.util.Date;
import java.util.HashMap;
import java.util.Vector;

import com.data.AndroidDevice;
import com.data.Device;
import com.data.Interview;
import com.data.User;
import com.server.common.AndroidDeviceInfo;
import com.test.TestConfig;

public class MockDBQueries {

	User u;
	Device d;
	Vector<User> users;
	Vector<Device> devices;
	HashMap<String, String> m;
	Interview i1;
	Interview i2;
	Interview i3;
	Vector<Interview> interviews;
	User u5;
	User u51;
	User u10;

	public MockDBQueries() {
		u = new User("jdoe", "password");
		u.setRetrivalInterval(5);
		m = new HashMap<String, String>();
		d = new AndroidDevice(u.getId(), m);
		u.addDevice(d);
		devices = new Vector<Device>();
		devices.add(d);
		users = new Vector<User>();
		users.add(u);
		interviews = new Vector<Interview>();
		u5 = new User(TestConfig.USER_ID, TestConfig.USER_PWD);
		u51 = new User(TestConfig.USER1_ID, TestConfig.USER1_PWD);
		u10 = new User(TestConfig.USER2_ID, TestConfig.USER2_PWD);
		u5.addDevice(d);
		u51.addDevice(d);
		u10.addDevice(d);

		i1 = new Interview(u, "00151853", "08 JUN 2011");
		i1.setEmployerName("QUALCOMM Inc");
		i1.setJobDescription("This is a simple description for testing");
		i1.setJobTitle("SE Developer");
		i1.setType("In person");
		i1.setStatus("Screened");
		i1.setLength(45);
		i1.setLocation("TC 3232");

		i2 = new Interview(u, "00151888", "10 JUN 2011");
		i2.setEmployerName("Avvasi");
		i2.setJobDescription("This is another simple description. MUAHAHAHA");
		i2.setJobTitle("Developer");
		i2.setType("In person");
		i2.setStatus("Screened");
		i2.setLength(30);
		i2.setLocation("TC 2027");

		i3 = new Interview(u, "00152089", "01 JUN 2011");
		i3.setEmployerName("Univiersity of Waterloo");
		i3.setJobDescription("This is an awesome tutor position offered by the University of Waterloo.");
		i3.setJobTitle("CS246 Tutor");
		i3.setType("In person");
		i3.setStatus("Screened");
		i3.setLength(30);
		i3.setLocation("DC 3030");

		interviews.add(i1);
		interviews.add(i2);
		interviews.add(i3);
	}

	public boolean execMockDBQuery() {
		return true;
	}

	public boolean storeToDB() {
		return true;
	}

	public User getUserFromDB() {
		return u;
	}

	public Vector<User> getUserCollectionFromDB() {
		User u = new User("id", "pwd");
		Vector<User> collection = new Vector<User>();
		collection.add(u);

		return collection;
	}

	public Interview getInterviewFromDB(String jobId) {
		if (i1.getJobID().equals(jobId)) {
			return i1;
		} else if (i2.getJobID().equals(jobId)) {
			return i2;
		} else if (i3.getJobID().equals(jobId)) {
			return i3;
		}
		return null;
	}

	public Vector<Interview> getInterviewCollectionFromDB() {
		return interviews;
	}

	public boolean saveUser(User u1) {
		devices = u1.getDevice();
		users.remove(0);
		users.add(u1);
		d = devices.get(0);
		u = u1;
		return true;
	}

	public boolean saveUserDeviceRegID(String userID, int deviceId, String regID) {
		d.addAttribute(AndroidDeviceInfo.REGISTRATION_ID, regID);
		return true;
	}

	public boolean updateCheckedTime(Date newTime, User usr) {
		u.setLastCheckedTime(newTime);
		return true;
	}

	public Vector<User> getUsersByInterval(int interval) {

		Vector<User> collection = new Vector<User>();
		if (interval == 5) {
			collection.add(u5);
			collection.add(u51);
		} else if (interval == 10) {
			collection.add(u10);
		}
		return collection;
	}

}